//
//  PhotoViewController.m
//  时光电影项目
//
//  Created by 墨狂之逸才 on 15/7/23.
//  Copyright (c) 2015年 墨狂之逸才. All rights reserved.
//

#import "PhotoViewController.h"
#define Kheight  [UIScreen mainScreen].bounds.size.height
#define kwidth  [UIScreen mainScreen].bounds.size.width


@interface PhotoViewController ()

@end

@implementation PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self _creatNavButton];
    
    [self _creatCollectionView];
    
    //添加观察者
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hiddenNavgationBar) name:@"hiddenNavgationBar" object:nil];
    
    // Do any additional setup after loading the view.
}

- (void)hiddenNavgationBar
{
    BOOL isHidden = self.navigationController.navigationBar.isHidden;
    [self.navigationController.navigationBar setHidden:!isHidden];
    
}

- (void)_creatCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    
    layout.itemSize = self.view.frame.size;
    
    
    //设置滑动方向,因为UICollectionView是UIScrollView的子类，所以也有这个属性
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    layout.minimumLineSpacing = 30;
    
//    _collectionView.delegate = self;
//    _collectionView.dataSource = self;
    //现在提倡为控制器瘦身，就是控制器内部view要实现的方法，就不要在控制器里面实现了
    //子类化一个UICollectionView，UICollectionView要显示的内容，让他自己来加载，只要传递给他数据就好了，数据作为他的属性
    

    
    _collectionView = [[PhotoCollectionView alloc]initWithFrame:CGRectMake(0, 0, kwidth+30, Kheight) collectionViewLayout:layout];
    
    
    //只要讲数据传递给子类，其他事情，都交给子类PhotoCollectionView来完成
//    _collectionView.imageUrlArray = self.imageUrlArray;
    
    
    //传递数据
    _collectionView.imageUrlArray = _imageUrlArray;
    
    
    NSIndexPath *index = [NSIndexPath indexPathForRow:self.index inSection:0];
    
    [_collectionView scrollToItemAtIndexPath:index atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
    
    
    [self.view addSubview:_collectionView];
    
}

#pragma mark - set方法
- (void)setImageUrlArray:(NSArray *)imageUrlArray
{
    _imageUrlArray = imageUrlArray;
    
    //传递数据
    
    //这边又有_collectionView的set方法，所以要在PhotoCollectionView里面重写一下set 方法
    _collectionView.imageUrlArray = _imageUrlArray;
    
}

- (void)_creatNavButton
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(btnAction)];
    
    
    
}

- (void)btnAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
